home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3691 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: newshost.lanl.gov!usenet
  2. From: tkg@lanl.gov (Thomas K. Gamble)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: Pascal 'real' to C 'float'
  5. Date: 25 Jan 1996 14:46:05 GMT
  6. Organization: Los Alamos National Lab.
  7. Distribution: world
  8. Message-ID: <4e853d$iqb@newshost.lanl.gov>
  9. NNTP-Posting-Host: gamble.lanl.gov
  10. X-Newsreader: NeoLogic News for OS/2 [version: 4.2]
  11.  
  12. In message <4e674d$ett@maestro.netinc.ca> - swallace@netinc.ca (Shawn Wallace) 
  13. writes:
  14. >
  15. >I've run into a little difficulty converting the data from an older
  16. >Pascal program into C.
  17. >
  18. >I need to convert the pascal 'real' number (which I believe to be a
  19. >6-byte struct) to a C/C++ float or double (which are 4 and 8-bytes
  20. >respecively).
  21. >
  22. >I seem to remember the Turbo Pascal help files describing the exact
  23. >way a pascal 'real' is stored, but I no longer have that compiler.
  24. >Could anyone shed any light on this?  Please cc: any replies to my
  25. >email (just in case).
  26. >
  27. >Shawn
  28. >swallace@netinc.ca
  29. >
  30. >
  31.  
  32. "Complete Turbo Pascal," by Jeff Duntemann, desribes 6 byte reals
  33. as follows.
  34.  
  35.               byte#   0    1    2    3    4    5
  36.                      exp  lsb   (mantissa)    msb
  37.  
  38.  
  39.     "From low memory to high: The exponent is stored in the first byte,
  40.          followed by the least significant byte of the mantissa, the next most
  41.          significant byte, and so on, for five bytes of mantissa.  
  42.          Forty-bits-worth of mantissa will give you eleven significant 
  43.          figures.  Beyond that point, additional precition will be lost, 
  44.          although the exponent will always give you the correct order of 
  45.          magnitude to the limits of the range of type REAL."
  46.  
  47.  
  48. Hope this helps.
  49.  
  50. ********************************************************************************
  51. Thomas K. Gamble                                   tkg@lanl.gov, gamble@ibm.net
  52. member - TeamOS/2
  53.  
  54. "Club Windows?  I know a lot of people who would love to, and I suspect that not
  55. even environmentalists would protest." - Nicholas Petreley (InfoWorld 12/4/95)
  56. ********************************************************************************
  57.  
  58.